﻿using System.Linq;

namespace AutoCompleteTextBox
{
    public class AutocompleteArrayDataSource : AutocompleteDataSource
    {
        public override string RenderDataSource()
        {
            string listItems = null;

            var controls = Controls.OfType<AutocompleteArrayDataSourceItem>().ToList();

            foreach (AutocompleteArrayDataSourceItem c in controls)
                listItems += "'" + ((AutocompleteArrayDataSourceItem)c).GetItems() + "',";
            listItems = listItems.Substring(0, listItems.Length - 1);

            var so = GetSettingsObject();
            so.ClientID = ClientID.ToString();
            so.Source = "[" + listItems + "]";

            RegistrarClientScript.ClientScriptManager(Page, ClientID, so.GetString());

            return ClientID.ToString();
        }
    }
}
